#include "EbnProposition.h"
#include "EbnWorldState.h"


CEbnProposition::CEbnProposition(CEbnWorldState * worldState, bool positive)
{
    mpWorldState = worldState;
    mPositiveWorldState = positive;
    mWeight = 1;
}

CEbnProposition::~CEbnProposition(void)
{

}

CEbnWorldState * CEbnProposition::getWorldState()
{
    return mpWorldState;
}

float CEbnProposition::getValue()
{
    float value = 0;

    if (mpWorldState)
    {

        if (true == mPositiveWorldState)
        {
            value = mpWorldState->getTruthValue();
        }
        else
        {
            value = (1 - mpWorldState->getTruthValue());
        }

    }

    return value;
}

bool CEbnProposition::isPositiveWorldState()
{
    return mPositiveWorldState;
}

bool CEbnProposition::isSame(CEbnProposition * proposition)
{
    if (proposition)
    {
        if(getWorldState() == proposition->getWorldState())
        {
            return true;
        }
    }

    return false;
}

bool CEbnProposition::isIdentical(CEbnProposition * proposition)
{
    if (true == isSame(proposition))
    {
        if (isPositiveWorldState() == proposition->isPositiveWorldState())
        {
                return true;
        }
    }

    return false;
}

bool CEbnProposition::isInverse(CEbnProposition * proposition)
{
    if (true == isSame(proposition))
    {
        if (isPositiveWorldState() != proposition->isPositiveWorldState())
        {
            return true;
        }
    }

    return false;
}

string CEbnProposition::getName()
{
    if (mpWorldState)
    {
        return mpWorldState->getName();
    }

    return NULL;
}

void CEbnProposition::setWorldState()
{
    if (mpWorldState)
    {

       if (true == mPositiveWorldState)
       {
            mpWorldState->setTruthValue(1.0);
       }
       else
       {
            mpWorldState->setTruthValue(0.0);
       }

    }

}

float CEbnProposition::getWeight(void)
{
    return mWeight;
}

void CEbnProposition::setWeight(float weight)
{
    mWeight = weight;
}
